package com.cangmaomao.lib.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.cangmaomao.lib.utils.dp2px

class CustomView : View {

    private var color: Int = Color.RED

    private val paint = Paint()

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    fun setColor(color: Int) {
        this.color = color
        this.invalidate()
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        paint.color = color
        paint.style = Paint.Style.FILL
        paint.isAntiAlias = true
        val cx = width / 2f
        val cy = height / 2f
        canvas.drawCircle(cx, cy, context.dp2px(18f), paint)

    }


}